<template>
  <div class="app-container">

    <u-page title="商户管理">
      <div slot="header">
        <el-button type="primary" icon="el-icon-edit" @click="hdlOpen(newForm)">
          {{ textMap['create'] }}
        </el-button>
      </div>

      <u-filtered>
        <el-form ref="listQuery" :inline="true" :model="listQuery" class="search-form">
          <el-form-item label="楼层" prop="floor">
            <mall-floor v-model="listQuery.floor" />
          </el-form-item>
          <el-form-item label="商户" prop="name">
            <el-input v-model="listQuery.name" placeholder="关键词查询" clearable />
          </el-form-item>
          <el-form-item label="收银台" prop="cashdeskNo">
            <el-input v-model="listQuery.cashdeskNo" placeholder="收银台" clearable style="width: 140px" />
          </el-form-item>
          <el-form-item label="首字母" prop="firstLetter">
            <el-input v-model="listQuery.firstLetter" placeholder="首字母" clearable maxlength="1" show-word-limit style="width: 140px" />
          </el-form-item>
          <el-form-item label="部门编码" prop="deptCode">
            <el-input v-model="listQuery.deptCode" placeholder="部门编码" clearable style="width: 140px" />
          </el-form-item>
          <el-form-item label="收银员编码" prop="cashdeskCode">
            <el-input v-model="listQuery.cashdeskCode" placeholder="收银员编码" clearable style="width: 140px" />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="listQuery.status" clearable>
              <el-option label="全部" value="" />
              <el-option label="正常" :value="true" />
              <el-option label="撤柜" :value="false" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="hdlFilter">搜索</el-button>
          </el-form-item>
        </el-form>
      </u-filtered>

      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      >
        <template v-slot:right>
          <el-table-column label="操作" align="center" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="text" @click="hdlEdit(row)">编辑</el-button>
              <el-button type="text" @click="hdlDelete(row.id, row.name)">删除</el-button>
            </template>
          </el-table-column>
        </template>
      </u-table>
    </u-page>

    <u-dialog :title="textMap[dialogStatus]" :show.sync="dialogFormVisible" @confirm="dialogStatus === 'create' ? hdlCreate() : hdlUpdate()">
      <el-form ref="dialogForm" :rules="rules" :model="dataForm" label-width="150px">
        <el-form-item prop="floor" label="商场楼层">
          <mall-floor v-model="dataForm.floor" width="100%" />
        </el-form-item>
        <el-form-item prop="name" label="商户名称">
          <el-input v-model="dataForm.name" placeholder="商户名称" clearable maxlength="10" show-word-limit />
        </el-form-item>
        <el-form-item prop="firstLetter" label="首字母">
          <el-input v-model="dataForm.firstLetter" placeholder="商户名称首字母" clearable maxlength="1" show-word-limit />
        </el-form-item>
        <el-form-item prop="code" label="商户编码">
          <el-input v-model="dataForm.code" placeholder="商户编码(二维火)" clearable />
        </el-form-item>
        <el-form-item prop="deptCode" label="部门编码">
          <el-input v-model="dataForm.deptCode" placeholder="部门编码" clearable maxlength="10" show-word-limit />
        </el-form-item>
        <el-form-item prop="cashdeskCode" label="收银员">
          <el-input v-model="dataForm.cashdeskCode" placeholder="收银员编码" clearable maxlength="8" show-word-limit />
        </el-form-item>
        <el-form-item prop="cashdeskNo" label="收银台">
          <el-input v-model="dataForm.cashdeskNo" placeholder="收银台" clearable maxlength="3" show-word-limit />
        </el-form-item>
        <el-form-item prop="goodsId" label="商品ID">
          <el-input v-model="dataForm.goodsId" placeholder="商品ID" clearable />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="dataForm.status">
            <el-radio :label="true">正常</el-radio>
            <el-radio :label="false">撤柜</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
    </u-dialog>

  </div>
</template>
<script>
import MallFloor from '@/components/mall/floor.vue'

export default {
  components: {
    MallFloor
  },
  data() {
    return {
      api: this.$u.api.PluginsDfireMerchant,
      // 表格
      columns: [
        {
          prop: 'floor',
          label: '楼层'
        },
        {
          prop: 'name',
          label: '商户名称'
        },
        {
          prop: 'firstLetter',
          label: '首字母'
        },
        {
          prop: 'code',
          label: '商户编码'
        },
        {
          prop: 'deptCode',
          label: '部门编码'
        },
        {
          prop: 'cashdeskCode',
          label: '收银员编码'
        },
        {
          prop: 'cashdeskNo',
          label: '收银台'
        },
        {
          prop: 'goodsId',
          label: '商品ID'
        },
        {
          prop: 'createdAt',
          label: '创建时间',
          timestamp: true
        },
        {
          prop: 'status',
          label: '状态',
          render: (h, params) => {
            if (params.row.status) {
              return h('el-tag', { props: { type: 'success' }}, '正常')
            } else {
              return h('el-tag', { props: { type: 'danger' }}, '撤柜')
            }
          }
        }
      ],
      list: [],
      listLoading: false,
      listOptions: {
        index: true,
        stripe: true // boolean 斑马纹
      },
      listQuery: {
        pageNumber: 1,
        pageSize: 10,
        totalCount: 1,
        name: '',
        status: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑商户',
        create: '新增商户'
      },
      dataForm: {},
      rules: {
        floor: [{ required: true, message: '选择楼层', trigger: ['blur'] }],
        firstLetter: [{ required: true, message: '商户首字母', trigger: ['blur'] }],
        name: [{ required: true, message: '商户名称', trigger: ['blur'] }],
        code: [{ required: true, message: '商户编码', trigger: ['blur'] }],
        deptCode: [{ required: true, message: '部门编码', trigger: ['blur'] }],
        status: [{ required: true, message: '请选择状态', trigger: ['blur'] }],
        cashdeskCode: [{ required: true, message: '收银员编码', trigger: ['blur'] }],
        cashdeskNo: [{ required: true, message: '收银台', trigger: ['blur'] }],
        goodsId: [{ required: true, message: '商品ID', trigger: ['blur'] }]
      },
      newForm: {
        status: true
      }
    }
  },
  created() {
    this.hdlList()
  }
}
</script>
